<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>
 
<span ><a href="<?php echo url('notification/write'); ?>">写通知</a></span>

<form action="<?php echo url('notification/edit'); ?>" method="post" name="form" 
        onsubmit="
		if (this.notification_name.value == '') { 
		alert('请输入通知标题'); 
		return false; }
		else { 
			if (this.notification_desc.value == '') 
			{ 
			alert('请输入通知内容'); 
			return false; 
			}
			return true; 
		}" enctype="multipart/form-data">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
		<td><span class="defaultbold">通知标题</span><br /></td>
		<td><input class="input" type="text" name="notification_name" value="<?php echo $noti->notification_name ?>" id="name" size="58" /></td>
	</tr>
  <input type="hidden" name="notification_id" id="notification_id" value="<?php echo $noti->id() ?>" />
	<tr>
		<td><span class="defaultbold">发给部门</span><br /></td>
		<td>
		<select name="department_id" id="department_id">
			<?php if (-1 == $noti->department_id): ?>
			<option value="-1" id="-1" selected="selected" >
				所有部门
			</option>
				<?php else: ?>
			<option value="-1" id="-1">
				所有部门
			</option>

			<?php endif; ?>
			<?php foreach ($deps as $depd): ?>
			    <?php if ($depd->id() == $noti->department_id): ?>
				<option value="<?php echo $depd->department_id ?>" selected="selected" id="<?php echo $depd->department_id ?>">
					<?php echo $depd->department_name; ?>
				</option>
				<?php else: ?>
				<option value="<?php echo $depd->department_id ?>" id="<?php echo $depd->department_id ?>" >
					<?php echo $depd->department_name; ?>
				</option>
				<?php endif; ?>
			<?php endforeach; ?>


		</select>
        <span><a onclick="displaydep()" id="disp_or_hide">显示部门成员</a></span>

		</td>
	</tr>
	<tr>
        <td></td>
        <td height="auto">
                <div id="user_select"  style="display:none">
                        
                </div>
        </td>
        </tr>
    <tr>                                                                                                               
                <td><span class="defaultbold ">在通知末尾自动追加时间</span><br /></td>
                <td><input class="input" type="checkbox" name="append_time" checked="checked"/></td>
    </tr> 

		<tr>
		<td><span class="defaultbold ">通知内容</span><br /></td>
		<td><textarea name="notification_desc" rows="10" cols="45" ><?php echo $noti->notification_desc ?></textarea></td>
	</tr>
    <tr>
		<td><span class="defaultbold ">重新发送</span><br /></td>
	</tr>
	<tr>
		<td class="tbutton" colspan="2"><input type="submit" value="确认发送" class="btn" name="submit"> </td>
	</tr>
		</table>
</form>

<script language="javascript">
    var xmlHttp = false;
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    document.getElementById("department_id").onchange=_f;

    function _f()
    {   
      var dep_id = document.getElementById("department_id").value;

      var url = "<?php echo url('Notification/getuserfromdepid'); ?>";
      var poststr="&dep_id=" + escape(dep_id);

      // Open a connection to the server
      xmlHttp.open("POST", url, true);
      xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

      // Setup a function for the server to run when it's done
      xmlHttp.onreadystatechange = updatePage;
      
      // Send the request
      xmlHttp.send(poststr);
    }

    function displaydep()
    {   
      var dep_id = -1;
      var objSrc = document.getElementById ("disp_or_hide");
      var objDiv = document.getElementById ("user_select");
      if (objDiv.style.display== "none")
      {
          objDiv.style.display = "";
          objSrc.innerHTML = "隐藏部门成员";
      }
      else
      {
          objDiv.style.display = "none";
          objSrc.innerHTML = "显示部门成员";
      }
      return _f();
    }
    function updatePage() {
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
          var response_str = xmlHttp.responseText;
          //从服务端返回json的数据,组织为html
          //'user_id':10,
          //'user_name':李宜章,
          if(response_str.length == 0)
          {
              alert("该部门目前没有职员");
              document.getElementById("department_id").value = -1;
              return;
          }
        
          $('#user_select').html(response_str);
      }
    }
</script>
<?php $this->_endblock(); ?>
